package org.youisoft.summer.evaluator.impl;
import java.util.Map;
import java.util.Properties;
import org.youisoft.summer.evaluator.PlaceHolder;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.StringOperator;
import org.youisoft.summer.evaluator.unit.AbstractParenthesis;
import org.youisoft.summer.evaluator.util.Ulitity;


/**
 * 
 * @author zijiang.jl
 *
 *
 *
 */
public class MapResouceParenthesis extends AbstractParenthesis<Map<String,Object>,Properties>{
	
	@Override
	protected <C> Operator<?> resolveVarPlaceHolder(
			CalContext<C, Map<String, Object>, Properties> context,
			StringOperator so){
		if(so.value().startsWith(PlaceHolder.instance.getVarPlaceHolder())&&
				so.value().endsWith(PlaceHolder.instance.getVarPlaceHolder())){
			String temp=so.value().substring(1,so.value().length()-1);
			if(this.property!=null&&this.property.get(temp)!=null){
				String key=this.property.get(temp).toString().trim();
				return Ulitity.smartWrapResource(resource.get(key));
			}else{
				if(resource!=null) return Ulitity.smartWrapResource(resource.get(temp));
			}

		} 
                          
		return so;
	
	}

}
